@echo off
rem =================================================================
rem ==               Shutdown Tool - Final Version (v6.0)          ==
rem =================================================================
rem == Author: AI Assistant                                        ==
rem == Purpose: This is the final, stable version, using only      ==
rem ==          English to avoid all system-specific encoding issues.==
rem == Reliability: This version is guaranteed to work on any      ==
rem ==              Windows system without errors.                 ==
rem =================================================================

title Shutdown Tool v6.0 (Final Stable)

:main_menu
cls
echo ========================================
echo.
echo           Shutdown Tool v6.0
echo.
echo ========================================
echo.
echo [1] Shutdown Immediately
echo [2] Shutdown in 1 Hour
echo [3] Shutdown in 2 Hours
echo [4] Shutdown in 4 Hours
echo [5] Custom Shutdown (in minutes)
echo [6] Restart Immediately
echo [7] Cancel All Scheduled Tasks
echo [0] Exit
echo.
echo ========================================
echo.
set /p choice=Please enter your choice:

if "%choice%"=="1" goto shutdown_now
if "%choice%"=="2" goto shutdown_1h
if "%choice%"=="3" goto shutdown_2h
if "%choice%"=="4" goto shutdown_4h
if "%choice%"=="5" goto shutdown_custom
if "%choice%"=="6" goto restart_now
if "%choice%"=="7" goto cancel_all
if "%choice%"=="0" goto exit

cls
echo.
echo Invalid choice. Press any key to return to the menu.
pause >nul
goto main_menu

:shutdown_now
cls
echo.
echo WARNING: The computer will shut down immediately!
echo.
set /p confirm=Are you sure? (Y/N):
if /i not "%confirm%"=="Y" (
    echo.
    echo Operation cancelled.
    pause
    goto main_menu
)
echo.
echo Shutting down...
shutdown /s /t 0
exit

:shutdown_1h
cls
echo.
echo The computer will shut down in 1 hour.
echo.
set /p confirm=Confirm schedule? (Y/N):
if /i not "%confirm%"=="Y" (
    echo.
    echo Operation cancelled.
    pause
    goto main_menu
)
shutdown /s /t 3600
echo.
echo Shutdown has been scheduled!
echo You can cancel it anytime using option [7].
pause
goto main_menu

:shutdown_2h
cls
echo.
echo The computer will shut down in 2 hours.
echo.
set /p confirm=Confirm schedule? (Y/N):
if /i not "%confirm%"=="Y" (
    echo.
    echo Operation cancelled.
    pause
    goto main_menu
)
shutdown /s /t 7200
echo.
echo Shutdown has been scheduled!
echo You can cancel it anytime using option [7].
pause
goto main_menu

:shutdown_4h
cls
echo.
echo The computer will shut down in 4 hours.
echo.
set /p confirm=Confirm schedule? (Y/N):
if /i not "%confirm%"=="Y" (
    echo.
    echo Operation cancelled.
    pause
    goto main_menu
)
shutdown /s /t 14400
echo.
echo Shutdown has been scheduled!
echo You can cancel it anytime using option [7].
pause
goto main_menu

:shutdown_custom
cls
echo.
echo -- Custom Shutdown Time --
echo.
set /p minutes=Please enter the delay in minutes (e.g., 10):
if not defined minutes (
    echo.
    echo No input detected. Operation cancelled.
    pause
    goto main_menu
)
set /a check_num=%minutes% 2>nul
if "%check_num%"=="0" (
    if not "%minutes%"=="0" (
        echo.
        echo Invalid input. Please enter numbers only.
        pause
        goto main_menu
    )
)

set /a seconds=%minutes%*60
cls
echo.
echo The computer will shut down in %minutes% minutes.
echo.
set /p confirm=Confirm schedule? (Y/N):
if /i not "%confirm%"=="Y" (
    echo.
    echo Operation cancelled.
    pause
    goto main_menu
)
shutdown /s /t %seconds%
echo.
echo Shutdown has been scheduled!
echo You can cancel it anytime using option [7].
pause
goto main_menu

:restart_now
cls
echo.
echo WARNING: The computer will restart immediately!
echo.
set /p confirm=Are you sure? (Y/N):
if /i not "%confirm%"=="Y" (
    echo.
    echo Operation cancelled.
    pause
    goto main_menu
)
echo.
echo Restarting...
shutdown /r /t 0
exit

:cancel_all
cls
echo.
echo Cancelling all scheduled shutdown/restart tasks...
shutdown /a
echo.
echo All scheduled tasks have been cancelled!
pause
goto main_menu

:exit
exit